package kr.co.mcshop.option;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@RequestMapping(value="/admin")
@Controller
public class OptionController {
	
	@Autowired
	OptionService optionService;
	
	
	@RequestMapping(value="/OptionList")
	public String OptionList(@RequestParam Map map, Model model){
		System.out.println(map);
		List optionList = optionService.getAllOption(map);
		model.addAttribute("optionList", optionList);
		model.addAttribute("optionAmount", optionList.size());
		return "admin/option/OptionListForm";	
	}
	
	@RequestMapping(value="/OptionInsertForm")
	public String OptionInsertForm(@RequestParam Map map, Model model){
		return "admin/option/OptionInsertForm";	
	}
	
	@RequestMapping(value="OptionInsert")
	public String OptionInsert(@RequestParam Map map){
		System.out.println(map);
		optionService.InsertOption(map);
		return "redirect:/admin/OptionList";
	}
	
	@RequestMapping(value="OptionEditForm")
	public String OptionEditForm(@RequestParam Map map,Model model){
		List list = optionService.getAllOption(map);
		Map optionList = (Map) list.get(0);
		Integer no = (Integer) optionList.get("no");
		optionList.put("no", no.intValue());	
		model.addAttribute("optionList", optionList);
		return "admin/option/OptionEditForm";
	}
	
	@RequestMapping(value="OptionEdit")
	public String OptionEdit(@RequestParam Map map){
		System.out.println(map);
		optionService.UpdateOption(map);
		return "redirect:/admin/OptionList";
	}
	
	@RequestMapping(value="OptionDelete")
	public String OptionDelete(@RequestParam Map map){
		optionService.DeleteOption(map);
		return "redirect:/admin/OptionList";
	}
}
